package com.railway.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.railway.bean.LoseCreditUser;
import com.railway.bean.Vo;
import com.railway.service.LoseCreditService;
import com.railway.service.impl.LoseCreditServiceImpl;
import com.railway.util.JSONUtil;
@WebServlet("/LoseCreditReload.do")
public class LoseCreditReloadServlet extends HttpServlet{

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("UTF-8");
		String key = req.getParameter("key");
		int pageNum,pageSize;
		if(req.getParameter("page") == null) {
			pageNum = 1;
		}else {
			pageNum = Integer.parseInt(req.getParameter("page"));
		}
		

		if(req.getParameter("limit") == null) {
			pageSize = 10;
		}else {
			pageSize = Integer.parseInt(req.getParameter("limit"));
		}
		LoseCreditService lcus = new LoseCreditServiceImpl();
		List<LoseCreditUser> lcuList = lcus.selectLcuLimit(key, pageNum, pageSize);
		Vo<LoseCreditUser> vo = new Vo();
		vo.setCode(0); 
		vo.setMsg("success");
		vo.setData(lcuList); 
		vo.setCount(lcus.selectCountLcu(key));
		JSONUtil.responJSOn(resp, vo);
	}
	
}
